package com.aseo.business.hibernate;

import java.util.List;
import java.util.Set;

import javax.annotation.Resource;
import javax.validation.ConstraintViolation;

import org.springframework.stereotype.Service;

import com.aseo.exception.ConstraintViolationException;
import com.aseo.model.dao.Dao;
import com.aseo.model.entity.hibernate.ParadaVehiculo;

@Service
public class ParadaVehiculoManager implements ManagerInterface<ParadaVehiculo> {

	@Resource  
	private Dao dao;
	
	@Override
	public List<ParadaVehiculo> getAll() {
		final List<ParadaVehiculo> list = dao.find(ParadaVehiculo.class);  
	    return list;
	}

	@Override
	public void persist(ParadaVehiculo t) {
		dao.persist(t);
	}
	
	public void validate(ParadaVehiculo paradaVehiculo) throws ConstraintViolationException {

		Set<ConstraintViolation<ParadaVehiculo>> constraintViolations = dao.validate(paradaVehiculo);
		
		for (ConstraintViolation<ParadaVehiculo> constraintViolation : constraintViolations) {
			throw new ConstraintViolationException(constraintViolation.getMessage());
		}
	}

}
